//
//  RealNameController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/10/26.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "RealNameController.h"
#import "ActullyNameController.h"

@interface RealNameController ()
@property (weak, nonatomic) IBOutlet UITextField *nameText;
@property (weak, nonatomic) IBOutlet UITextField *idText;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;

@end

@implementation RealNameController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)nextAction:(UIButton *)sender {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"real_name":self.nameText.text,@"card_id":self.idText.text,@"token":self.userToken};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@member/user-verify",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            ActullyNameController * vc = [[ActullyNameController alloc]init];
            vc.verifyKeyString = [responseObject objectForKey:@"data"][@"user_verify_redis_key"];
            [self.navigationController pushViewController:vc animated:YES];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
    
}

-(void)setNavi
{
    self.title = @"实名认证";
}

-(void)setUI
{
    self.view.backgroundColor = Color(245, 245, 245);
    
    self.nameText.placeholder = @"请输入您的真实姓名";
    self.nameText.textAlignment = NSTextAlignmentCenter;
    self.nameText.borderStyle = UITextBorderStyleRoundedRect;
    
    self.idText.placeholder = @"请输入您的身份证号码";
    self.idText.textAlignment = NSTextAlignmentCenter;
    self.idText.borderStyle = UITextBorderStyleRoundedRect;
    
    [self.idText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
    
    [self.nameText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
}

- (void)textFieldDidChange:(UITextField *)textField
{
    
    if (self.nameText.text.length && self.idText.text.length) {
        self.nextBtn.userInteractionEnabled = YES;
        [self.nextBtn setBackgroundColor:MainColor];
    }else
    {
        [self.nextBtn setBackgroundColor:MainBtnColor];
        self.nextBtn.userInteractionEnabled = NO;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
